package com.justnow.offer;

/**
 * @author justnow
 * Created on 2020-09-23
 * Description
 */
public class Wbzx01 {
    public int indexOf (String s, String pattern) {
        // write code here
        if (s == null || pattern == null) {
            return -1;
        }
        if (s.length() < pattern.length()) {
            return -1;
        }

        int lengthS = s.length();
        int lengthPattern = pattern.length();
        int result = -1;
        for (int i = 0; i < lengthS; i++) {
            if (s.charAt(i) == pattern.charAt(0)) {
                boolean flag = true;
                int tempi = i + 1;
                int tempj = 1;
                while (tempi < lengthS && tempj < lengthPattern) {
                    if (s.charAt(tempi) == pattern.charAt(tempj)) {
                        tempi++;
                        tempj++;
                    } else {
                        flag = false;
                        break;
                    }
                }

                if (flag) {
                    return i;
                }

            } else {
                continue;
            }
        }

        return -1;

    }
}
